import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

var state = window.localStorage.getItem('state')
if (state) {
  state = JSON.parse(state)
}

export default new Vuex.Store({
  state: state ? state : {
    lang: 'zh',
    userinfo: null
  },
  mutations: {
    setLang (state, lang) {
      state.lang = lang
      window.localStorage.setItem('state', JSON.stringify(state))
    },
    logout (state) {
      state.userinfo = null
      window.localStorage.setItem('state', JSON.stringify(state))
    },
    setUserInfo (state, info) {
      state.userinfo = info
      window.localStorage.setItem('state', JSON.stringify(state))
    }
  },
  getters: {
    getLang (state) {
      return state.lang
    },
    getUserInfo (state) {
      return state.userinfo
    }
  },
  actions: {
  },
  modules: {
  }
})
